package com.xinnet.mms.customerManage.service.impl;

import java.io.Serializable;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.locks.ReentrantReadWriteLock;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xinnet.core.utils.page.PageView;
import com.xinnet.mms.allot.dao.CustomMixDao;
import com.xinnet.mms.allot.service.CustomAllotService;
import com.xinnet.mms.config.dao.FlowTurnConfigDao;
import com.xinnet.mms.customerManage.dao.CustomerManageDao;
import com.xinnet.mms.customerManage.service.CustomerManageService;
import com.xinnet.mms.customercare.dao.CustomerCareDao;
import com.xinnet.mms.dept.dao.DeptDao;
import com.xinnet.mms.dept.service.DeptService;
import com.xinnet.mms.deptarea.dao.DeptAreaDao;
import com.xinnet.mms.empcustomrelation.dao.EmpCustomRelationDao;
import com.xinnet.mms.entity.Area;
import com.xinnet.mms.entity.CustomMixAudit;
import com.xinnet.mms.entity.Customer;
import com.xinnet.mms.entity.CustomerCare;
import com.xinnet.mms.entity.CustomerRemark;
import com.xinnet.mms.entity.Dept;
import com.xinnet.mms.entity.Emp;
import com.xinnet.mms.entity.EmpCustomRelation;
import com.xinnet.mms.entity.Product;
import com.xinnet.mms.entity.PublicConfig;
import com.xinnet.mms.entity.PushHistory;
import com.xinnet.mms.entity.PushResults;
import com.xinnet.mms.entity.ShopCart;
import com.xinnet.mms.enums.CustomerTypeEnmu;
import com.xinnet.mms.enums.ProductTypeEnum;
import com.xinnet.mms.login.dao.EmpDao;
import com.xinnet.mms.member.service.MemberService;
import com.xinnet.mms.order.dao.OrderDao;
import com.xinnet.mms.shopcart.dao.ShopcartDao;
import com.xinnet.mms.utils.CustomerManage;

@Service("customerManageService")
public class CustomerManageServiceImpl implements CustomerManageService,Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 3776313645521761556L;

	@Autowired
	private CustomerManageDao customerManageDao;

	@Autowired
	private CustomerCareDao customerCareDao;

	@Autowired
	private transient FlowTurnConfigDao flowTurnConfigDao;

	@Autowired
	private transient EmpDao empDao;

	@Autowired
	private CustomAllotService customAllotService;
	
	@Autowired
	private transient OrderDao orderDao;
	@Autowired
	private ShopcartDao shopcartDao;
	@Autowired
	private transient DeptDao deptDao;
	
	@Autowired
	private transient DeptAreaDao deptAreaDao;
	
	@Autowired
	private EmpCustomRelationDao empCustomRelationDao;
	
	@Autowired
	private CustomMixDao  customMixDao;
	/** 会员中心 */
	@Autowired
	private MemberService memberService;
	
	
	private ReentrantReadWriteLock readWriteLock = new ReentrantReadWriteLock();
	
	private static Log log = LogFactory.getLog(CustomerManageServiceImpl.class);
	
	@Autowired
	private DeptService deptService;
	
	
	@Override
	public PageView<Customer> queryCustomer(PageView<Customer> pageView,
			Customer customer) throws Exception {

		List<Customer> customerList = new ArrayList<Customer>();
		Integer customerType = customer.getCustomerType();
		String areaId = customer.getRegionalId();
		if(null == areaId || "".equals(areaId) || "null".equals(areaId)) {
			customer.setRegionalId(null);
		}

		
		//查询新注册客户 需要看allotType属性 0 为查询所有新注册客户 1为首次分配新注册客户 2为二次分配新注册客户
		if(null != customer.getAllotType() && !"".equals(customer.getAllotType())) {
			customer.setCustomerType(null);
		}
		//查询会员购物车
		if(customerType.equals(CustomerManage.CUSTOMER_SHOP_CART)) {
			// 具体的客户类型
			customer.setCustomerType(customer.getCustomType());
			customer.setNotInType(CustomerManage.NOT_REGISTER_NEW_CUSTOMER);
			customer.setCustomState(CustomerManage.ACCEPT_YES);
			customer.setCustomType(CustomerManage.CUSTOMER_SHOP_CART);
		}
		
		//记录总条数
		Integer rowCount = 0;
		
		// 查询报备客户
		if (customerType.equals(CustomerManage.REPORTED_CUSTOMER)) {
			rowCount = customerManageDao.getReportedCustomerCount(customer);
			customerList = customerManageDao.queryReportedCustomer(pageView,
					customer);
		} else {
			
			//如果商品和到期时间不为空，则从会员查出来符合商品和到期时间条件的会员号
			String productCode = customer.getProductCode();
			String startDueTime = customer.getStartDueTime();
			String endDueTime = customer.getEndDueTime();
			if(startDueTime!=null && !"".equals(startDueTime) && endDueTime!=null && !"".equals(endDueTime) ){
				customer.setStartDueTime(startDueTime+" 00:00:00");
				customer.setEndDueTime(endDueTime+" 23:59:59");
				if(productCode!=null && !"".equals(productCode)){
					List<Customer> customList = orderDao.getCusIdByExpireDate(customer);
					if(customList!=null && !customList.isEmpty()){
						List<String> customIdList = new ArrayList<String>();
						for(Customer custom : customList){
							customIdList.add(custom.getCusId());
						}
						customer.setCustomIdList(customIdList);
					} else {
						pageView.setRecords(customerList);
						return pageView;
					}
				} else {
					List<Customer> customList = new ArrayList<Customer>();;
					List<Customer> customList1 = orderDao.getNYZJCusIdByExpireDate(customer);
					List<Customer> customList2 = orderDao.getZJZYCusIdByExpireDate(customer);
					List<Customer> customList3 = orderDao.getMCusIdByExpireDate(customer);
					List<Customer> customList4 = orderDao.getVCusIdByExpireDate(customer);
					List<Customer> customList5 = orderDao.getDCusIdByExpireDate(customer);
					List<Customer> customList6 = orderDao.getV_MEJZCusIdByExpireDate(customer);
					List<Customer> customList7 = orderDao.getCHIYUNCusIdByExpireDate(customer);
					
					customList.addAll(customList1);
					customList.addAll(customList2);
					customList.addAll(customList3);
					customList.addAll(customList4);
					customList.addAll(customList5);
					customList.addAll(customList6);
					customList.addAll(customList7);
					if(!customList.isEmpty()){
						List<String> customIdList = new ArrayList<String>();
						for(Customer custom : customList){
							customIdList.add(custom.getCusId());
						}
						customer.setCustomIdList(customIdList);
					} else {
						pageView.setRecords(customerList);
						return pageView;
					}
				}
				
			}
			
			// 获取客户列表
			rowCount = customerManageDao.count(customer);
			customerList = customerManageDao.getCustomerList(pageView, customer);
			for(Customer c:customerList) {
				Product product = customAllotService.getProductByProductCode(c.getProductLabel());
				Customer member = memberService.getMemberByCusId(c.getCustomId());
				if(member!=null){
					c.setOrganizeNameCN(member.getOrganizeNameCN());
				}
				if(null != product) {
					c.setProductName(product.getProductName());
				}else {
					c.setProductName("");
				}
				
				//计算未联系天数，首先查询有没有交流记录
				CustomerRemark customerRemark = new CustomerRemark();
				customerRemark.setCusId(c.getCustomId());
				List<CustomerRemark> remarkList = this.queryCustomerRemark(customerRemark);
				if(remarkList!=null && remarkList.size()>0){
					//取时间最大的作为最后一次交流时间
					CustomerRemark remark = remarkList.get(0);
					
					String remarkAddTime = remark.getAddTime();
					 /* 先转成毫秒并求差 */
			        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			        long m = new Date().getTime() - sdf.parse(remarkAddTime).getTime();
			        
			        System.out.println("相差天数:"+ ( m / (1000 * 60 * 60 * 24) ) );
			        c.setNolinkedDay(String.valueOf(m / (1000 * 60 * 60 * 24)));
				} else {
					String addTime = c.getAddTime();
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			        long m = new Date().getTime() - sdf.parse(addTime).getTime();
			        
			        System.out.println("相差天数:"+ ( m / (1000 * 60 * 60 * 24) ) );
			        c.setNolinkedDay(String.valueOf(m / (1000 * 60 * 60 * 24)));
				}
				
			}
			//按加入购物车时间查的要过滤重复的会员
			if(customer.getAddShopCartStartTime()!=null && !"".equals(customer.getAddShopCartStartTime())){
				Map<String, Customer> scMap = new HashMap<String, Customer>();
				for(Customer c:customerList) {
					scMap.put(c.getCustomId(), c);
				}
				//customerList
				List<Customer> tmpList = new ArrayList<Customer>();
				for (Iterator<Customer> iterator = scMap.values().iterator(); iterator
						.hasNext();) {
					Customer customerTmp = (Customer) iterator.next();
					tmpList.add(customerTmp);
				}
				customerList=tmpList;
			}
		}
		
		Integer pageNow = pageView.getPageNow();
		Integer pageSize = pageView.getPageSize();
		Integer pageCount = (rowCount + pageSize - 1) / pageSize;
		
		if(customerType.equals(CustomerManage.CUSTOMER_SHOP_CART)) {
			pageView.setPageNow(pageNow);
			pageView.setPageCount(pageCount);
			pageView.setRowCount(rowCount);
		}
		for (Customer c : customerList) {
			//分页参数
			c.setPageNow(pageNow);
			c.setRowCount(rowCount);
			c.setPageSize(pageSize);
			c.setPageCount(pageCount);
			//将null值设置为空字符串
			//手机
			if(null == c.getPhone()) {
				c.setPhone("");
			}
			if(null == c.getPushDesc()) {
				c.setPushDesc("");
			}
			
			// 设置客户所属人员
			Emp emp = empDao.getEmpbyEmpno(c.getEmpId());
			if(null != emp && null != emp.getEname()) {
				c.setEmpName(emp.getEname());
			}
			
//			if(customerType.equals(CustomerManage.SERVICE_CUSTOMER)) {
//				Product product = customerManageDao.getProductByProductId(c.getProductId());
//				if(null != product) {
//					c.setProductName(product.getProductName());
//				}else {
//					c.setProductName("");
//				}
//			}
			
			// 设置客户类型(查询会员购物车跟即将流走客户时)
			String customerTypeStr = null;
			if(customerType.equals(CustomerManage.CUSTOMER_SHOP_CART) || customerType.equals(CustomerManage.VANISH_SOON_CUSTOMER)) {
				if(null != c.getCustomType()) {
					CustomerTypeEnmu customerTypeEnmu = CustomerTypeEnmu.getCustomerTypeEnmuByValue(c.getCustomType());
					if(null != customerTypeEnmu) {
						customerTypeStr = customerTypeEnmu.getLabel();
						c.setCustomerTypeStr(customerTypeStr);
					}
						
				}else if(null != customerType) {
					CustomerTypeEnmu customerTypeEnmu = CustomerTypeEnmu.getCustomerTypeEnmuByValue(customerType);
					if(null != customerTypeEnmu) {
						customerTypeStr = customerTypeEnmu.getLabel();
						c.setCustomerTypeStr(customerTypeStr);
					}
				}
			}
			
			//获取二次开发客户的已购商品
			if(customerType.equals(CustomerManage.TIMESET_CURRENT)) {
				EmpCustomRelation empCustomRelation = new EmpCustomRelation();
				empCustomRelation.setCustomId(c.getCustomId());
				empCustomRelation.setCustomType(CustomerManage.SERVICE_CUSTOMER);
				List<String> ecrList = empCustomRelationDao.getBuyProduct(empCustomRelation);
				
				String productStr = "";
				
				if(null != ecrList && ecrList.size() > 0) {
					// 设置已购商品 用","分隔
					int size = ecrList.size();
					for (int i = 0; i < size; i++) {
						if (null != ecrList.get(i)) {

							if (i == size - 1) {
								productStr += ecrList.get(i);
							} else {
								productStr += ecrList.get(i) + ",";
							}
						}
					}
					c.setProductName(productStr);
				}
			}
			
			// 获取客户的意向商品 (意向客户、新注册客户、未注册新客户)
			if (customerType.equals(CustomerManage.INTENTION_CUSTOMER)
					|| customerType.equals(CustomerManage.NEW_CUSTOMER)
					|| customerType
							.equals(CustomerManage.NOT_REGISTER_NEW_CUSTOMER)) {
				List<Product> intentionProductList = null;
				String intentionProduct = "";
				intentionProductList = customerManageDao.getIntentionProduct(c
						.getCustomId());

				if (null != intentionProductList
						&& intentionProductList.size() > 0) {

					int size = intentionProductList.size();
					// 设置意向商品 用","分隔
					for (int i = 0; i < size; i++) {
						if (null != intentionProductList.get(i)) {

							if (i == size - 1) {
								intentionProduct += intentionProductList.get(i)
										.getProductName();
							} else {
								intentionProduct += intentionProductList.get(i)
										.getProductName() + ",";
							}
						}
					}
					c.setProductName(intentionProduct);
				}
				intentionProduct = "";
			}
		}
		pageView.setRecords(customerList);
		return pageView;
	}

	@Override
	public List<Customer> queryCustomer(Customer customer) throws Exception {
		List<Customer> customerList = null;
		//记录总条数
		Integer rowCount = 0;
		// 获取客户列表
		rowCount = customerManageDao.getCustomerCount(customer);
		customerList = customerManageDao.getCustomerList(customer);
		for(Customer cus : customerList){
			//客户名称从会员数据库中获得，根据会员号查询
			Customer member = memberService.getMemberByCusId(cus.getCustomId());
			if(member!=null){
				cus.setOrganizeNameCN(member.getOrganizeNameCN());
			}
			
		}
		customer.setRowCount(rowCount);
		return customerList;
	}

	@Override
	public List<ShopCart> queryShopCartCustomer(ShopCart shopCart) throws Exception {
		int count = shopcartDao.getShopCartCustomerCount(shopCart);
		shopCart.setRowCount(count);
		return shopcartDao.queryShopCartCustomer(shopCart);
	}
	
	@Override
	public Customer addReportedCustomer(Customer customer) {

		/*List<Customer> existsCustomer = this.customerManageDao
				.queryCustomerByPhoneOrEmail(customer);*/
		Customer existsCustomer1 = this.customerManageDao
				.queryCustomerByPhone(customer);
		Customer existsCustomer2 = this.customerManageDao
				.queryCustomerByEmail(customer);
		/*Customer existsCustomer = this.customerManageDao.queryCustomerByPhone(customer);
		Customer existsCustomer2 = this.customerManageDao.queryCustomerByEmail(customer);*/
		if (null == existsCustomer1 && null == existsCustomer2) {
			customer.setCusId(UUID.randomUUID().toString());
			this.customerManageDao.addCustomer(customer);
		}
		if(existsCustomer1 != null){
			return existsCustomer1;
		} 
		if( existsCustomer2 != null){
			return existsCustomer2;
		} 
		
		return null;
	}

	@Override
	public void delCustomerByIds(String customerIdStr) {

		Customer customer = new Customer();
		String[] cusIdArray = customerIdStr.split(":");
		customer.setCusIdArray(cusIdArray);
		this.customerManageDao.delCustomerByIds(customer);
	}

	@Override
	public void accept(Customer customer) {

		String[] cusIdArray = customer.getCusIdStr().split(":");
		String[] pushHistoryIdArray = customer.getPhIdStr().split(":");
		String[] pusherIdArray = customer.getPusherIdStr().split(":");
		// 实例化客户销售关系实体类
		EmpCustomRelation empCustomRelation = new EmpCustomRelation();
		int length = cusIdArray.length;
		for (int i = 0; i < length; i++) {
			customer.setCusId(cusIdArray[i]);
			customer.setIsAllot(CustomerManage.ALLOT_YES);
			// 将客户表中该记录的“是否被分配”字段设为已分配
			this.customerManageDao.modifyCustomerById(customer);

			PushHistory pushHistory = new PushHistory();
			pushHistory.setId(pushHistoryIdArray[i]);
			pushHistory.setIsReceive(CustomerManage.ACCEPT_YES);
			// 将客户表中该记录的“是否接收”字段设为已接收
			this.customerManageDao.updatePushHistoryById(pushHistory);

			// 设置人员客户ID
			empCustomRelation.setId(UUID.randomUUID().toString());
			// 设置客户ID
			empCustomRelation.setCustomId(customer.getCusId());
			// 设置负责人--当前登录用户ID
			empCustomRelation.setEmpId(customer.getEmpno());
			// 设置推送人ID
			empCustomRelation.setPusherId(pusherIdArray[i]);
			// 设置推送产品ID
			// empCustomRelation.setProductId(productId);

		}

	}

	@Override
	public Customer getById(Long id) {

		return null;
	}

	@Override
	public Customer findByCustomerName(String customerName) {

		return null;
	}

	public List<Customer> getAllCustom() {
		List<Customer> customerList = customerManageDao.getAllCustom();
		return customerList;

	}

	@Override
	public void updateCustomer(Customer customer) {
		customerManageDao.updateCustomer(customer);
	}

	@Override
	public void updateCustomerProduct(Customer customer) {
		// TODO 自动生成的方法存根
		customerManageDao.updateCustomerProduct(customer);
	}


	@Override
	public void goOpenSea(Customer customer) {
		customerManageDao.goOpenSea(customer);

	}

	@Override
	public void addEmpCustomer(Customer customer, Emp emp) {

		// EmpCustomer empCustomer = new EmpCustomer();
		// // 设置人员客户表ID
		// empCustomer.setEmpCusId(UUID.randomUUID().toString());
		// // 设置客户ID
		// empCustomer.setCusId(customer.getCusId());
		// // 获取当前时间字符串
		// String now = DateUtil.getFormatDate("yyyy-MM-dd HH:mm:ss");
		// // 设置归属时间
		// empCustomer.setBelongTime(now);
		// // 设置负责人--当前登录用户ID
		// empCustomer.setEmpno(emp.getEmpno());
		// // 设置推送人ID
		// empCustomer.setPushEmpId(customer.getPusherId());
		// // 设置开发方式
		// empCustomer.setDevelopmentType(4);
		//
		// this.customerManageDao.addEmpCustomer(empCustomer);
	}

	@Override
	public List<Dept> getDeptByProductIds(String[] productIds,String companyId) {

		List<String> strList = new ArrayList<String>();
		for (int i = 0; i < productIds.length; i++) {
			strList.add(productIds[i]);
		}
		Dept dept = new Dept();
		dept.setProductIdList(strList);
		dept.setCompanyIdStr(companyId);
		return customerManageDao.getDeptByProductIds(dept);
	}

	public void delCustomByCname(String customName) {
		customerManageDao.delCustomByCname(customName);
	}

	public void addCustom(Customer customer) {
		customerManageDao.addCustom(customer);
	}

	@Override
	public int modifyReportedCustomer(Customer customer) {

		int flag = 0;
		Customer existsCustomer = this.customerManageDao
				.queryCustomerByPhoneAndEmail(customer);
		// 如果手机+邮箱在客户表里没有查到相应的客户 则可以修改
		// 如果查到有相应的客户 则必须是当前修改的客户 否则 不允许修改
		if (null != existsCustomer
				&& !existsCustomer.getCusId().equals(customer.getCusId())) {

		} else {
			this.customerManageDao.modifyCustomerById(customer);
			flag = 1;
		}
		return flag;

	}

	public List<Customer> getOfServiceCustomerByEmpNoStr(String empNoStr) {
		List<Customer> customerList = customerManageDao
				.getOfServiceCustomerByEmpNoStr(empNoStr);
		return customerList;
	}

	public int addCustomMixAudit(CustomMixAudit customMixAudit) {
//		WriteLock writeLock = readWriteLock.writeLock();
		try {
//			writeLock.lock();
			String ecrId = customMixAudit.getEcrId();
			customMixDao.updateCustomMixAuditByEcrId(ecrId);
			String fromEmpId = customMixAudit.getFromEmpId();
			List<CustomMixAudit> customMixAuditList = customerManageDao.getCustomMixAuditByEcrIdAndFromEmpId(ecrId,fromEmpId);
			if(customMixAuditList!=null && customMixAuditList.size()>0){
				return 0;
			}
			customerManageDao.addCustomMixAudit(customMixAudit);
			return 1;
		} catch (Exception e) {
			log.error("调配操作失败："+e.getMessage(), e);
			return 0;
		}finally{
//			writeLock.unlock();
		}
	}

	public List<CustomMixAudit> getAllCustomMixAudit() {
		List<CustomMixAudit> customMixAuditList = customerManageDao
				.getAllCustomMixAudit();
		return customMixAuditList;
	}

	public List<Customer> getDeployCustomByParam(Map<String, Object> param) {
		List<Customer> customerList = customerManageDao.getDeployCustomByParam(param);
		return customerList;
	}
	public Integer  getDeployCustomCountByParam(Map<String, Object> param){
		Integer count = customerManageDao.getDeployCustomCountByParam(param);
		return count;
		
	}

	public List<CustomMixAudit> getCustomDeployApprovalItems(String deptIdStr,String approvalerId) {
		//customerManageDao.updateCustomMixAuditStatusByDeptIdStr(deptIdStr);
		List<CustomMixAudit> customMixAuditList = customerManageDao.getCustomDeployApprovalItems(deptIdStr,approvalerId);
		return customMixAuditList;
	}

	public List<CustomMixAudit> getCustomMixAudit(Map<String, Object> param) {
		List<CustomMixAudit> customMixAuditList = customerManageDao
				.getCustomMixAudit(param);
		return customMixAuditList;
	}
	
	public Integer getCustomMixAuditCount(Map<String,Object> param){
		return customerManageDao.getCustomMixAuditCount(param);
	}

	public int updateCustomMixAudit(CustomMixAudit customMixAudit) throws Exception {
		return customerManageDao.updateCustomMixAudit(customMixAudit);
	}

	@Override
	public List<Area> getAreaByDeptId(String deptId) {

		return this.customerManageDao.getAreaByDeptId(deptId);
	}

	@Override
	public List<Product> getProductByParentId(String parentId) {

		return this.customerManageDao.getProductByParentId(parentId);
	}

	@Override
	public List<CustomerCare> getCustomerCareListByCondition(
			CustomerCare customerCare) {

		return this.customerManageDao
				.getCustomerCareListByCondition(customerCare);
	}

	@Override
	public List<Product> getNotPushProductByCustomerId(String cusId) {

		return this.customerManageDao.getNotPushProductByCustomerId(cusId);
	}

	@Override
	public PageView<CustomerRemark> queryCustomerRemark(
			PageView<CustomerRemark> pageView, CustomerRemark customerRemark,
			Emp emp) {

		if (null == emp || null == customerRemark) {
			return null;
		}
		customerRemark.setEmpId(emp.getEmpno());
		List<CustomerRemark> customerRemarkList = this.customerManageDao
				.queryCustomerRemark(pageView, customerRemark);
		pageView.setRecords(customerRemarkList);
		return pageView;
	}

	@Override
	public List<CustomerRemark> queryCustomerRemark(CustomerRemark customerRemark) {

		List<CustomerRemark> customerRemarkList = this.customerManageDao
				.queryCustomerRemark(customerRemark);
		return customerRemarkList;
	}
	
	@Override
	public void addCustomerRemark(CustomerRemark customerRemark) {

		this.customerManageDao.addCustomerRemark(customerRemark);
	}

	@Override
	public List<Customer> getCustomerByIdArray(String[] cusIdArray) {

		Customer customer = new Customer();
		customer.setCusIdArray(cusIdArray);
		return customerManageDao.getCustomerByIdArray(customer);
	}

	@Override
	public void modifyCustomerById(Customer customer) {

		this.customerManageDao.modifyCustomerById(customer);
	}

	@Override
	public void modifyCustomerRemarkById(CustomerRemark customerRemark) {

		this.customerManageDao.modifyCustomerRemarkById(customerRemark);
	}

	/** 删除400客户 */
	@Override
	public void del400Customer(String cusId) {
		customerManageDao.del400Customer(cusId);
	}

	@Override
	public List<PushResults> getPushNumber(PushResults pushResults) {

		return customerManageDao.getPushNumber(pushResults);
	}

	@Override
	public List<Emp> getEmpListByDeptId(String deptId) {

		return customerManageDao.getEmpListByDeptId(deptId);
	}

	public void customDeployApproval(String id, String isEffect) throws Exception {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("id", id);
		List<CustomMixAudit> customMixAuditList = customerManageDao.getCustomMixAudit(param);
		CustomMixAudit customMixAudit = customMixAuditList.get(0);
		String cusId = customMixAudit.getCusId();
		String operationContent = customMixAudit.getOperationContent();
		if (operationContent != null && !"".equals(operationContent)) {
			String deptIdAndEmpNo = operationContent.split(",")[1];
			// String currentDeptNo = deptIdAndEmpNo.split("_")[0];

			String currentEmpNo = deptIdAndEmpNo.split("_")[0];
			String deployDeptId = deptIdAndEmpNo.split("_")[1];
			String deployEmpNo = deptIdAndEmpNo.split("_")[2];
			Customer customer = new Customer();
			customer.setCusId(cusId);
			customer.setEmpno(currentEmpNo);
			customer.setMixEmpno(deployEmpNo);
			customer.setMixDeptno(deployDeptId);
			// customAllotService.allot(customer, CustomerManage.Mix_CUSTOMER);
			customAllotService.doMixCoustomer(customer);
		}
		CustomMixAudit customMixAuditParam = new CustomMixAudit();
		customMixAuditParam.setIsEffect(isEffect);
		customMixAuditParam.setId(id);
		customerManageDao.updateCustomMixAudit(customMixAuditParam);
	}

	public void customDeployBathApproval(String idStr, String isEffect) throws Exception {
		String[] idStrArray = idStr.split(",");
		for (int i = 0; i < idStrArray.length; i++) {
			String id = idStrArray[i];
			Map<String, Object> param = new HashMap<String, Object>();
			param.put("id", id);
			List<CustomMixAudit> customMixAuditList = customerManageDao
					.getCustomMixAudit(param);
			CustomMixAudit customMixAudit = customMixAuditList.get(0);
			String cusId = customMixAudit.getCusId();
			String operationContent = customMixAudit.getOperationContent();
			if (operationContent != null && !"".equals(operationContent)) {
				String deptIdAndEmpNo = operationContent.split(",")[1];
				// String currentDeptId = deptIdAndEmpNo.split("_")[0];

				String currentEmpNo = deptIdAndEmpNo.split("_")[1];
				String deployDeptId = deptIdAndEmpNo.split("_")[2];
				String deployEmpNo = deptIdAndEmpNo.split("_")[3];
				Customer customer = new Customer();
				customer.setCusId(cusId);
				customer.setEmpno(currentEmpNo);
				customer.setMixEmpno(deployEmpNo);
				customer.setMixDeptno(deployDeptId);
				// customAllotService.allot(customer,
				// CustomerManage.Mix_CUSTOMER);
			}

			CustomMixAudit customMixAuditParam = new CustomMixAudit();
			customMixAuditParam.setIsEffect(isEffect);
			customMixAuditParam.setId(id);
			customerManageDao.updateCustomMixAudit(customMixAuditParam);
		}
	}

	@Override
	public void updateIsRecyclingByCusId(String cusId) {

		customerManageDao.updateIsRecyclingByCusId(cusId);
	}

	@Override
	public String getDeptChildrenId(String deptId) {
		String deptIdStr = "";
		Dept dept = null;

		// 若是没有ID为此ID的部门 则直接返回null
		dept = deptDao.getDeptByDeptId(deptId);
		if (null == dept) {
			return null;
		}

		String id = dept.getId();

		deptIdStr += id;

		List<Dept> tempList = empDao.getDeptByParentId(deptId);

		// 如果该部门没有子部门 则返回该部门
		if (null == tempList || tempList.size() == 0) {
			return deptIdStr;
		}

		// 如果该部门有子部门 则返回该部门及其子部门
		for (Dept d : tempList) {
			deptIdStr += "," + getDeptChildrenId(d.getId());
		}

		return deptIdStr;
	}

	@Override
	public PushHistory getPushHistoryById(String pushHistoryId) {
		return customerManageDao.getPushHistoryById(pushHistoryId);
	}

	@Override
	public Product getProductByProductId(String productId) {

		return customerManageDao.getProductByProductId(productId);
	}

	@Override
	public PageView<Customer> getCustomerByEmpIdAndCustomState(
			PageView<Customer> page, Customer customer) {

		page.setRecords(customerManageDao.getCustomerByEmpIdAndCustomState(
				page, customer));
		return page;
	}

	@Override
	public List<Product> getAllProduct() {

		return customerManageDao.getAllProduct();
	}

	@Override
	
	//public List<Customer> getDeployCustomByDeptIdAndApplyerId(String deptIdStr,String applyerId){
	public List<Customer> getDeployCustomByMap(Map<String,Object> paramMap){
		//customerManageDao.updateCustomMixAuditStatusByDeptIdStr(deptIdStr);
		List<Customer> deployCustomList = customerManageDao.getDeployCustomByMap(paramMap);
		return deployCustomList;
	}
	
	public Integer getDeployCustomCountByMap(Map<String,Object> paramMap){
		
		Integer count = customerManageDao.getDeployCustomCountByMap(paramMap);
		return count;
	}

	public Customer getDeployCustomByCustomMixId(String customMixId) {
		Customer customer = customerManageDao
				.getDeployCustomByCustomMixId(customMixId);
		return customer;
	}

	@Override
	public List<Customer> getAllNotAcceptCustom(Customer customer) {
		//customer.setCustomState(CustomerManage.ACCEPT_NO);
		return customerManageDao.getAllNotAcceptCustom(customer);
	}


	@Override
	public PageView<Customer> queryDueSoonGoods(PageView<Customer> pageView,
			Customer customer) throws Exception {
	
		List<Customer> customerList = new ArrayList<Customer>();
		Integer dueWarningTime = Integer.parseInt(flowTurnConfigDao
				.getWarningTime().getConfigValue());
		//设置到期提醒时间
		customer.setDueWarningTime(dueWarningTime);
		Calendar cal = Calendar.getInstance(); 
		cal.setTime(new Date());
		if(customer.getDueWarningTime()!=null){
			cal.add(Calendar.DATE, customer.getDueWarningTime());
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			String vanishTimeStr = sdf.format(cal.getTime());
			customer.setVanishTime(vanishTimeStr);
		}
		//获取客户ID集合
		EmpCustomRelation empCustomRelation = new EmpCustomRelation();
		empCustomRelation.setCustomType(CustomerManage.SERVICE_CUSTOMER);
		if(customer.getCompanyId()!=null && !"".equals(customer.getCompanyId())){
			List<String> areaIdList = new ArrayList<String>();
			String[] strs = customer.getCompanyId().split(",");
			areaIdList.addAll(Arrays.asList(strs));
			customer.setAreaIdList(areaIdList);
		}
		Integer rowCount = 0;
		if(null != customer.getEmpId() && !"".equals(customer.getEmpId())) {
			/*empCustomRelation.setEmpId(customer.getEmpId());
			//empCustomRelation.setProductCode(customer.getProductLabel());
			List<EmpCustomRelation> empCustomRelationList = empCustomRelationDao.getEmpCustomRelationListByCondition(empCustomRelation);
			
			if(null != empCustomRelationList && empCustomRelationList.size() > 0) {
				for(EmpCustomRelation e : empCustomRelationList) {
					customIdList.add(e.getCustomId());
				}
				customer.setCustomIdList(customIdList);
			}*/
			
			//如果没有服务器客户 就没有即将到期客户
			String productLabel = customer.getProductLabel();
			if(ProductTypeEnum.Hosting.getValue().equalsIgnoreCase(productLabel)) {
				rowCount = orderDao.getIdcCount(customer);
				customerList = orderDao.queryIdc(pageView, customer);
			}else if(ProductTypeEnum.Cloud.getValue().equalsIgnoreCase(productLabel) || ProductTypeEnum.VPS.getValue().equalsIgnoreCase(productLabel) ) {
				rowCount = orderDao.getIdcServerHostingCount(customer);
				customerList = orderDao.queryIdcServerHosting(pageView, customer);
			}else if(ProductTypeEnum.Mailbox.getValue().equalsIgnoreCase(productLabel)) {
				rowCount = orderDao.getMailboxCount(customer);
				customerList = orderDao.queryMailbox(pageView, customer);
			}else if(ProductTypeEnum.Vhost.getValue().equalsIgnoreCase(productLabel)) {
				rowCount = orderDao.getVhostCount(customer);
				customerList = orderDao.queryVhost(pageView, customer);
			}else if(ProductTypeEnum.ChiYun.getValue().equalsIgnoreCase(productLabel)) {
				rowCount = orderDao.getChiYunCount(customer);
				customerList = orderDao.queryChiYun(pageView, customer);
			}else if(ProductTypeEnum.Domain.getValue().equalsIgnoreCase(productLabel)) {
				rowCount = orderDao.getDomainCount(customer);
				customerList = orderDao.queryDomain(pageView, customer);
			}else if(ProductTypeEnum.Jianzhan.getValue().equalsIgnoreCase(productLabel)) {
				rowCount = orderDao.getJianzhanCount(customer);
				customerList = orderDao.queryJianzhan(pageView, customer);
			}else {
				rowCount = orderDao.getIdcCount(customer);
				customerList = orderDao.queryIdc(pageView, customer);
				rowCount += orderDao.getIdcServerHostingCount(customer);
				List<Customer> l1 = orderDao.queryIdcServerHosting(pageView, customer);
				if(l1!=null&&!l1.isEmpty()){
					customerList.addAll(l1);
				}
				
				rowCount += orderDao.getMailboxCount(customer);
				List<Customer> l2 = orderDao.queryMailbox(pageView, customer);
				if(l2!=null&&!l2.isEmpty()){
					customerList.addAll(l2);
				}
				rowCount += orderDao.getVhostCount(customer);
				List<Customer> l3 = orderDao.queryVhost(pageView, customer);
				if(l3!=null&&!l3.isEmpty()){
					customerList.addAll(l3);
				}
				rowCount += orderDao.getChiYunCount(customer);
				List<Customer> l4 = orderDao.queryChiYun(pageView, customer);
				if(l4!=null&&!l4.isEmpty()){
					customerList.addAll(l4);
				}
				rowCount += orderDao.getDomainCount(customer);
				List<Customer> l5 = orderDao.queryDomain(pageView, customer);
				if(l5!=null&&!l5.isEmpty()){
					customerList.addAll(l5);
				}
				rowCount += orderDao.getJianzhanCount(customer);
				List<Customer> l6 = orderDao.queryJianzhan(pageView, customer);
				if(l6!=null&&!l6.isEmpty()){
					customerList.addAll(l6);
				}
			}
			
		}else {//部门负责人查询
			
			//empCustomRelation.setProductCode(customer.getProductLabel());
			String deptno = customer.getDeptId();
			
			if((customer.getCustomId()==null || "".equals(customer.getCustomId())) &&(customer.getEmpId()==null
					||"".equals(customer.getEmpId()))&&(customer.getStartDueTime()==null 
					||"".equals(customer.getStartDueTime())) && (customer.getEndDueTime()==null||"".equals(customer.getEndDueTime()))){
				pageView.setRecords(new ArrayList<Customer>());
				return pageView;
			}
			
			/*empCustomRelation.setDeptno(deptno);
			empCustomRelation.setCustomId(customer.getCustomId());
			empCustomRelation.setEmpId(customer.getEmpId());
			List<EmpCustomRelation> empCustomRelationList = empCustomRelationDao.getEmpCustomRelationListByCondition(empCustomRelation);
			if(null != empCustomRelationList && empCustomRelationList.size() > 0) {
				for(EmpCustomRelation e : empCustomRelationList) {
					customIdList.add(e.getCustomId());
				}
				customer.setCustomIdList(customIdList);
			}*/
			String productLabel = customer.getProductLabel();
			if(ProductTypeEnum.Hosting.getValue().equalsIgnoreCase(productLabel)) {
				rowCount = orderDao.getIdcCount(customer);
				customerList = orderDao.queryIdc(pageView, customer);
			}else if(ProductTypeEnum.Cloud.getValue().equalsIgnoreCase(productLabel) || ProductTypeEnum.VPS.getValue().equalsIgnoreCase(productLabel) ) {
				rowCount = orderDao.getIdcServerHostingCount(customer);
				customerList = orderDao.queryIdcServerHosting(pageView, customer);
			}else if(ProductTypeEnum.Mailbox.getValue().equalsIgnoreCase(productLabel)) {
				rowCount = orderDao.getMailboxCount(customer);
				customerList = orderDao.queryMailbox(pageView, customer);
			}else if(ProductTypeEnum.Vhost.getValue().equalsIgnoreCase(productLabel)) {
				rowCount = orderDao.getVhostCount(customer);
				customerList = orderDao.queryVhost(pageView, customer);
			}else if(ProductTypeEnum.ChiYun.getValue().equalsIgnoreCase(productLabel)) {
				rowCount = orderDao.getChiYunCount(customer);
				customerList = orderDao.queryChiYun(pageView, customer);
			}else if(ProductTypeEnum.Domain.getValue().equalsIgnoreCase(productLabel)) {
				rowCount = orderDao.getDomainCount(customer);
				customerList = orderDao.queryDomain(pageView, customer);
			}else if(ProductTypeEnum.Jianzhan.getValue().equalsIgnoreCase(productLabel)) {
				rowCount = orderDao.getJianzhanCount(customer);
				customerList = orderDao.queryJianzhan(pageView, customer);
			} else {
				rowCount = orderDao.getIdcCount(customer);
				customerList = orderDao.queryIdc(pageView, customer);
				rowCount += orderDao.getIdcServerHostingCount(customer);
				List<Customer> l1 = orderDao.queryIdcServerHosting(pageView, customer);
				if(l1!=null&&!l1.isEmpty()){
					customerList.addAll(l1);
				}
				
				rowCount += orderDao.getMailboxCount(customer);
				List<Customer> l2 = orderDao.queryMailbox(pageView, customer);
				if(l2!=null&&!l2.isEmpty()){
					customerList.addAll(l2);
				}
				rowCount += orderDao.getVhostCount(customer);
				List<Customer> l3 = orderDao.queryVhost(pageView, customer);
				if(l3!=null&&!l3.isEmpty()){
					customerList.addAll(l3);
				}
				rowCount += orderDao.getChiYunCount(customer);
				List<Customer> l4 = orderDao.queryChiYun(pageView, customer);
				if(l4!=null&&!l4.isEmpty()){
					customerList.addAll(l4);
				}
				rowCount += orderDao.getDomainCount(customer);
				List<Customer> l5 = orderDao.queryDomain(pageView, customer);
				if(l5!=null&&!l5.isEmpty()){
					customerList.addAll(l5);
				}
				rowCount += orderDao.getJianzhanCount(customer);
				List<Customer> l6 = orderDao.queryJianzhan(pageView, customer);
				if(l6!=null&&!l6.isEmpty()){
					customerList.addAll(l6);
				}
			}
		}
		
		Integer pageNow = pageView.getPageNow();
		Integer pageSize = pageView.getPageSize();
		Integer pageCount = (rowCount + pageSize - 1) / pageSize;
		
		//获取客户所属人
		//获取销售ID
		EmpCustomRelation forEmpName = new EmpCustomRelation();
		List<Customer> tempDelList=new ArrayList<Customer>();
		for(Customer c : customerList) {
			//设置分页
			c.setPageNow(pageNow);
			c.setRowCount(rowCount);
			c.setPageSize(pageSize);
			c.setPageCount(pageCount);
			
			c.setProductLabel(customer.getProductLabel());
			customAllotService.checkProduct(c);
			c.setProductCode(c.getProductLabel());
			Customer member = memberService.getMemberByCusId(c.getCustomId());
			if(member!=null){
				c.setOrganizeNameCN(member.getOrganizeNameCN());
			}
			forEmpName.setCustomId(c.getCustomId());
			forEmpName.setProductCode(customer.getProductLabel());
			List<EmpCustomRelation> ecrList = empCustomRelationDao.getEmpCustomRelationListByCondition(forEmpName);
			//找到产品不匹配的即将到期商品
			/*if(null == ecrList || ecrList.isEmpty()) {
				tempDelList.add(c);
			}*/
			Emp emp = null;
			for(EmpCustomRelation ecr : ecrList) {
				
				//根据销售ID获取销售
				emp = empDao.getEmpbyEmpno(ecr.getEmpId());
				if(null != emp) {
					if(null != customer.getEmpId() && !"".equals(customer.getEmpId())){
						if(!customer.getEmpId().equals(ecr.getEmpId())){
							//去除所查询的销售与查询结果的销售不一致的数据项
							tempDelList.add(c);
						}
					}
					c.setEmpName(emp.getEname());
					break ;
				}
				
			}
			//如果销售为空
			if(c.getEmpName() == null || "".equals(c.getEmpName())){
				//if(customer.getCompanyId()==null || "".equals(customer.getCompanyId())){
					if(customer.getDeptId()!=null && "zjl".equals(customer.getDeptId())){
						
					} else if(customer.getDeptId()!=null && "other".equals(customer.getDeptId())) {
					
					} else {
						tempDelList.add(c);
					}
					
				//}
			}
			
		}
		
		//去除产品不匹配的即将到期商品
		customerList.removeAll(tempDelList);
		pageView.setRowCount(rowCount);
		for (Customer customerSetPage : customerList) {
			customerSetPage.setRowCount(rowCount-tempDelList.size());
			customerSetPage.setPageCount((rowCount + pageSize - 1) / pageSize);
		}
		pageView.setRecords(customerList);
		return pageView;
	}


	@Override
	public Integer getAcceptNoCustomerCountByCustomType(Customer customer)
			throws Exception {
		//设置查询条件客户状态为未接收
		customer.setCustomState(CustomerManage.ACCEPT_NO);
		return customerManageDao.getAcceptNoCustomerCountByCustomType(customer);
	}

	@Override
	public Integer addShopCartCustomerCount(Customer customer)
			throws Exception {
		return customerManageDao.getAddShopCartCustomerCount(customer);
	}
	
	@Override
	public Integer getVanishSoonCustomerCount(Customer customer) throws SQLException {
		// 获取流走提醒时间
		PublicConfig config = flowTurnConfigDao.getPublicRemind();
		Integer vanishWarningTime = Integer.parseInt(config
				.getConfigValue());
		customer.setVanishWarningTime(vanishWarningTime);
		customer.setCustomState(CustomerManage.ACCEPT_YES);
		
		//设置查询条件客户状态为已接收
		customer.setCustomState(CustomerManage.ACCEPT_YES);
		return customerManageDao.getVanishSoonCustomerCount(customer);
	}


	@Override
	public PageView<Customer> queryOpenSeeCustomer(PageView<Customer> pageView,
			Customer customer) throws Exception {
		// 区域ID集合 用于公海客户查询时的区域权限
		List<String> areaIdList = new ArrayList<String>();
		//判断区域查询条件是否有效的标识
		int flag = 0;
		// 获取部门及其子部门所负责的区域
		String deptIdStr = deptService.getChildNodeId(customer.getDeptId());
		List<Area> tempAreaList = deptAreaDao
				.getAreaListByDeptIdStr(deptIdStr);
		
		String regionalId = customer.getRegionalId();
		if (null != tempAreaList && tempAreaList.size() > 0) {

			for (Area area : tempAreaList) {
				areaIdList.add(area.getAreaID());
				// 如果前台查询条件的区域并不在部门所负责的区域内 则无法查看
				if (null != regionalId
						&& regionalId.equals(
								area.getAreaID())) {
					flag = 1;
				}
			}
		}
		//如果所查询的区域不在当前登录人所属部门负责的区域内 则没有所查区域的权限 查不到数据
		if (flag != 1 && !regionalId.equals("")
				&& !regionalId.equals("null")) {
			//1 flag = 2表示没有所查区域的权限 所以查不到数据
			//2 如果deptId = null 则说明是总经理或副总经理查询 
			if(null != customer.getDeptId()) {
				flag = 2;
			}
			// 所属部门只负责一个区域 则只查询该区域
		} else if (flag == 1) {
			customer.setRegionalId(customer.getRegionalId());
			// 所属部门负责多个区域的话则查询多个区域
		} else if ((regionalId.equals("") || regionalId.equals("null")) && areaIdList.size() > 1) {
			customer.setRegionalId(null);
			customer.setAreaIdList(areaIdList);
		}
		
		//设置查询的客户类型为公海客户
		customer.setCustomType(CustomerManage.OPEN_SEA_CUSTOMER);
		//如果商品和到期时间不为空，则从会员查出来符合商品和到期时间条件的会员号
		String productCode = customer.getProductCode();
		String startDueTime = customer.getStartDueTime();
		String endDueTime = customer.getEndDueTime();
		if(productCode!=null && !"".equals(productCode) && startDueTime!=null && !"".equals(startDueTime) && endDueTime!=null && !"".equals(endDueTime) ){
			List<Customer> customList = orderDao.getCusIdByExpireDate(customer);
			if(customList!=null && !customList.isEmpty()){
				List<String> customIdList = new ArrayList<String>();
				for(Customer custom : customList){
					customIdList.add(custom.getCusId());
				}
				customer.setCustomIdList(customIdList);
			} else {
				List<Customer> customerList = new ArrayList<Customer>();
				pageView.setRecords(customerList);
				return pageView;
			}
		}
		//获取总记录数
		Integer rowCount = customerManageDao.getOpenSeeCustomerCount(customer);
		
		//获取数据列表
		List<Customer> list = customerManageDao.queryOpenSeeCustomer(pageView, customer);
		
		//设置分页
		Integer pageNow = pageView.getPageNow();
		Integer pageSize = pageView.getPageSize();
		Integer pageCount = (rowCount + pageSize - 1) / pageSize;
		
		int i = 1;
		for(Customer c : list) {
			if(i == 1) {
				//分页参数
				c.setPageNow(pageNow);
				c.setRowCount(rowCount);
				c.setPageSize(pageSize);
				c.setPageCount(pageCount);
				i ++;
			}
			
			Customer member = memberService.getMemberByCusId(c.getCustomId());
			if(member!=null){
				c.setPhone(member.getPhone());
				c.setEmail(member.getEmail());
				c.setCname(member.getCname());
				c.setCusId(c.getCustomId());
				customAllotService.updateCustomerInfo(c);
			}
			
			//计算未联系天数，首先查询有没有交流记录
			CustomerRemark customerRemark = new CustomerRemark();
			customerRemark.setCusId(c.getCustomId());
			List<CustomerRemark> remarkList = this.queryCustomerRemark(customerRemark);
			if(remarkList!=null && remarkList.size()>0){
				//取时间最大的作为最后一次交流时间
				CustomerRemark remark = remarkList.get(0);
				
				String remarkAddTime = remark.getAddTime();
				 /* 先转成毫秒并求差 */
		        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		        long m = new Date().getTime() - sdf.parse(remarkAddTime).getTime();
		        
		        System.out.println("相差天数:"+ ( m / (1000 * 60 * 60 * 24) ) );
		        c.setNolinkedDay(String.valueOf(m / (1000 * 60 * 60 * 24)));
			} else {
				String addTime = c.getAddTime();
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		        long m = new Date().getTime() - sdf.parse(addTime).getTime();
		        
		        System.out.println("相差天数:"+ ( m / (1000 * 60 * 60 * 24) ) );
		        c.setNolinkedDay(String.valueOf(m / (1000 * 60 * 60 * 24)));
			}
			
		}
		
		if(flag == 2) {
			pageView.setRecords(new ArrayList<Customer>());
		}else {
			pageView.setRecords(list);
		}
		return pageView;
	}
	
	public List<CustomMixAudit> getCustomDeployApprovalItemsByMap(Map<String,Object> paramMap){
		return customerManageDao.getCustomDeployApprovalItemsByMap(paramMap);
		
	}
	public Integer getCustomDeployApprovalItemsCountByMap(Map<String,Object> paramMap){
		return customerManageDao.getCustomDeployApprovalItemsCountByMap(paramMap);
		
	}

	@Override
	public Integer findAllfitCustomNum(Customer customer) {
		return customerManageDao.getAllfitCustomNum(customer);
	}

	@Override
	public List<Customer> findAllMindCustom(Customer customer) {
		return customerManageDao.getAllMindCustom(customer);
	}

	@Override
	public List<Customer> findAllWaitChargeCustom(Customer customer) {
		return customerManageDao.getAllWaitChargeCustom(customer);
	}

	@Override
	public List<Customer> findAllProtectCustom(Customer customer) {
		return customerManageDao.getAllProtectCustom(customer);
	}

	@Override
	public List<Customer> findAllSecondCustom(Customer customer) {
		return customerManageDao.getAllSecondCustom(customer);
	}
	
	public Integer getCustomerCount(Customer customer){
		return customerManageDao.getCustomerCount(customer);
	}


}
